<template>
  <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
    <BasicTable @register="registerTable" />
  </BasicModal>
</template>

<script lang="ts">
import { defineComponent, ref, computed, unref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm, Rule, useForm } from '/@/components/Form';
import { cloneDeep } from 'lodash-es';
import { BasicTable, useTable, TableAction, } from '/@/components/Table';

import { searchFormSchemaCheckSpot } from './data';
import { getCheckSpotList, } from '/@/api/project/planDetail';

export default defineComponent({
  name: 'checkSpotModal',
  components: { BasicModal, BasicTable },
  emits: ['success', 'register'],
  setup(_, { emit }) {
    const isUpdate = ref(true);

    //采样点位列表
    const [registerTable, { reload, }] = useTable({
      api: getCheckSpotList,
      columns: [{
        title: '检测项目',
        dataIndex: 'item',
      }, {
        title: '合同类别',
        dataIndex: 'contractType',
      }, {
        title: '检测点位',
        dataIndex: 'spot',
      }, {
        title: '点位数量',
        dataIndex: 'spotCount',
      }, {
        title: '频次',
        dataIndex: 'freq',
      }, {
        title: '周期',
        dataIndex: 'cycle',
      },],
      formConfig: {
        labelWidth: 120,
        schemas: searchFormSchemaCheckSpot,
        showAdvancedButton: false,
        showResetButton: false,
        autoSubmitOnEnter: true,
      },
      canColDrag: true,
      useSearchForm: true,
      bordered: true,
      showIndexColumn: true,
    });

    const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {

    });

    const getTitle = computed(() => (!unref(isUpdate) ? '新增' : '修改'));

    async function handleSubmit() {
      try {
        setModalProps({ confirmLoading: true });
        closeModal();
        emit('success');
      } finally {
        setModalProps({ confirmLoading: false });
      }
    }

    return { registerModal, registerTable, getTitle, handleSubmit };
  },
});
</script>
